package com.yuwubao.uav.tool.service.impl;

import com.yuwubao.framework.bean.PageData;
import com.yuwubao.uav.tool.mapper.PaternerMapper;
import com.yuwubao.uav.tool.service.PaternerService;
import com.yuwubao.uav.tool.util.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class PaternerServiceImpl implements PaternerService {

    private static final Logger logger = LogManager.getLogger(PaternerServiceImpl.class.getName());

    @Resource
    private PaternerMapper paternerMapper;

    @Override
    public void deletePaterner(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    paternerMapper.deletePaterner(pageData);
                }
            }

        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updatePaterner(PageData pageData) throws Exception {
        try{
            paternerMapper.updatePaterner(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void disableOrEnablePaterner(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    paternerMapper.disableOrEnablePaterner(pageData);
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void addPaterner(PageData pageData) throws Exception {
        try{
            paternerMapper.addPaterner(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listPaterner(PageData pageData) throws Exception {
        try{
            return paternerMapper.listPaterner(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listPaternerCount(PageData pageData) throws Exception {
        try{
            return paternerMapper.listPaternerCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }



    @Override
    public void disableOrEnablePaternerType(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    paternerMapper.disableOrEnablePaternerType(pageData);
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public void deletePaternerType(PageData pageData) throws Exception {
        try{
            String ids = pageData.get("ids") == null ? "" : pageData.getString("ids");
            if (StringUtil.isNotNvlOrBlank(ids)) {
                String[] idArr = ids.split(",");
                if (idArr != null && idArr.length>0) {
                    pageData.put("idArr",idArr);
                    paternerMapper.deletePaternerType(pageData);
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }
    @Override
    public void updatePaternerType(PageData pageData) throws Exception {
        try{
            paternerMapper.updatePaternerType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public void addPaternerType(PageData pageData) throws Exception {
        try{
            String names = pageData.get("names") == null ? "" : pageData.getString("names");
            if (StringUtil.isNotNvlOrBlank(names)) {
                String[] nameArr = names.split(",");
                if (nameArr != null && nameArr.length>0) {
                    int count = 0;
                    for (String name : nameArr) {
                        pageData.put("name",name);
                        count = paternerMapper.getPaternerTypeByName(pageData);
                        if (count == 0) {
                            paternerMapper.addPaternerType(pageData);
                        }
                    }
                }
            }
        }catch (Exception e) {
            logger.debug("",e);
        }
    }

    @Override
    public List<PageData> listPaternerType(PageData pageData) throws Exception {
        try{
            return paternerMapper.listPaternerType(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public List<PageData> listPaternerTypeAll(PageData pageData) throws Exception {
        try{
            return paternerMapper.listPaternerTypeAll(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return null;
    }
    @Override
    public int listPaternerTypeCount(PageData pageData) throws Exception {
        try{
            return paternerMapper.listPaternerTypeCount(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }
    @Override
    public int getPaternerByName(PageData pageData) throws Exception {
        try{
            return paternerMapper.getPaternerByName(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }
    @Override
    public int getPaternerTypeByName(PageData pageData) throws Exception {
        try{
            return paternerMapper.getPaternerTypeByName(pageData);
        }catch (Exception e) {
            logger.debug("",e);
        }
        return 0;
    }

}
